package cn.yzfy.service.impl;

import cn.yzfy.common.base.dto.BaseLongIdDTO;
import cn.yzfy.common.base.dto.BaseManyLongIdDTO;
import cn.yzfy.common.model.dto.AddRouteDTO;
import cn.yzfy.common.model.dto.EditRouteDTO;
import cn.yzfy.common.model.dto.RouteQueryPageDTO;
import cn.yzfy.common.model.entity.RouteEntity;
import cn.yzfy.common.model.vo.RouteVO;
import cn.yzfy.orm.mapper.RouteMapper;
import cn.yzfy.orm.utils.ModelMapperUtil;
import cn.yzfy.service.IRouteService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author 一朝风月
 * @date 2025/9/11 16:18
 * @Code 面向注解面向卿，终无解释再无你
 * @description bike骑行路线服务实现类
 */

@Service
@RequiredArgsConstructor
public class RouteServiceImpl implements IRouteService {
    private final RouteMapper routeMapper;
    @Override
    public Boolean addRoute(AddRouteDTO inputDTO) {
        RouteEntity addDTO= ModelMapperUtil.map(inputDTO, RouteEntity.class);
        routeMapper.insert(addDTO);
        return true;
    }

    @Override
    public Boolean delRoute(BaseManyLongIdDTO inputDTO) {
        routeMapper.deleteById(inputDTO.getIds());
        return null;
    }

    @Override
    public Boolean editRoute(EditRouteDTO inputDTO) {
        RouteEntity updateDTO= ModelMapperUtil.map(inputDTO, RouteEntity.class);
        routeMapper.updateById(updateDTO);
        return true;
    }

    @Override
    public Page<RouteVO> pageQueryList(RouteQueryPageDTO inputDTO) {
        LambdaQueryWrapper<RouteEntity>queryObj= Wrappers.lambdaQuery();
        return routeMapper.selectPage(inputDTO.toMybatisPageObject(), queryObj, RouteVO.class);

    }

    @Override
    public RouteVO getOne(BaseLongIdDTO inputDTO) {
        return routeMapper.selectById(inputDTO.getId(), RouteVO.class);
    }
}
